use futures::future::BoxFuture;
use tokio::sync::mpsc;
use tools::global_defin::tokio_runtime::get_rt;
use tracing::{span, Instrument, Level};

use crate::sip2::{dialog::sipdata::SipData, transport::TransportProtocol};

use super::{reg_ser::register_manage, SipRegEvent};

///注册处理管理器.这里可能是做为客户端,也可能做为服务端
pub(crate) fn start_sip_registe<F, F2>(
	handler_event: &'static F,
	get_user_passwd: F2,
) -> mpsc::Sender<(SipData, TransportProtocol)>
where
	F: Fn(SipRegEvent) -> () + Send + Sync,
	F2: Fn(&str) -> BoxFuture<Option<String>> + 'static + Send + Sync,
{
	let (sender, recv_command) = mpsc::channel(2048);

	let span = span!(Level::ERROR, "sip_reg");
	get_rt().spawn(register_manage(recv_command, handler_event, get_user_passwd).instrument(span));
	sender
}
